package com.itheima.线程安全.卖票;

//卖票任务类
public class Ticket implements Runnable {
    private int ticket =50;
  //  private Object obj=new Object();

    @Override
    public void run() {
        while (true) {
            synchronized ("同一把锁") {
                //锁对象

                if (ticket > 0) {
                   /* try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }*/
                    //卖票
                    ticket--;
                    //打印还剩多少张
                    System.out.println(Thread.currentThread().getName()+ "  正在出票，还剩 " + ticket + " 张票");
                } else {
                    break;
                }
            }
        }
    }
}
